package PersonInformation;
import java.util.Scanner;
public class Demo {
    public static void main(String[] args){
        //建造工具类
        Tool t=new Tool();
        //操作线性表对象
        PersonInformationListUse peruse=new PersonInformationListUse(10);
        //初始化对象列表
        PersonInformation p=new PersonInformation("gua",18,"女","12345678970");
        peruse.addList(p);

        boolean flag=true;
        Scanner sc=new Scanner(System.in);
        while(flag){
            t.menu();
            int key=sc.nextInt();
            switch(key){
                case 1://添加元素
                    System.out.println("姓名：");
                            String name=t.readName();
                    System.out.println("年龄：");
                    int age=t.readAge();
                    System.out.println("姓别：");
                    String gender=t.readGender();
                    System.out.println("电话号码：");
                    String Telephone=t.readTelephone();
                    PersonInformation Per=new PersonInformation(name,age,gender,Telephone);
                    peruse.addList(Per);
                    break;
                case 2://删除元素

                    while(true){
                        int index=sc.nextInt();
                        if(index-1>=peruse.getTotal()||index<=0){
                            System.out.println("输入坐标有误，请重新输入");
                        }
                        else{
                            peruse.deleteElem(index-1);
                            break;
                        }
                    }
                    break;
                case 3://查找单个元素
                    int index=sc.nextInt();
                    peruse.getPer(index-1);
                    break;
                case 4://更改元素
                    System.out.println("请输入更改元素下标");
                    int in=sc.nextInt();
                    System.out.println("姓名：");
                    String Name=t.readName();
                    System.out.println("年龄：");
                    int Age=t.readAge();

                    System.out.println("姓别：");
                    String Gender=t.readGender();
                    System.out.println("电话号码：");
                    String telephone=t.readTelephone();
                    PersonInformation newPer=new PersonInformation(Name,Age,Gender,telephone);
                    peruse.replace(in,newPer);
                    break;
                case 5://遍历数组
                    System.out.println("名字\t年龄\t性别\t电话号码");
                    for(int i=0;i<peruse.getTotal();i++){
                        System.out.println(peruse.per[i].name+"\t"+peruse.per[i].age+"\t"+peruse.per[i].gender+"\t"+peruse.per[i].telephone);
                    }
                    break;
                case 6:
                    flag=false;
                    break;
                default:
                    System.out.println("输入有误请重新输入");
                    break;

            }
        }
    }
}
